﻿using System;
using System.IO;

namespace FrameWork.Common.Files
{
    public class FileHelper
    {
        public static void WriteFile(object data)
        {
            try
            {
                string path = $@"D:\TokenLog\day{DateTime.Now:yyyy-MM-dd}";
                var filename = $"TokenLog{DateTime.Now:yyyy-MM-dd HH}.txt";
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);
                TextWriter tw = new StreamWriter(Path.Combine(path, filename), true); //true在文件末尾添加数据

                tw.WriteLine($"---------------------------------------------{DateTime.Now:yyyy-MM-dd HH:mm:ss}----------------------------");
                tw.WriteLine($"---------------------                                                          ------------------------");

                tw.WriteLine(data.ToJson());
                tw.Close();
            }
            catch (System.Exception e)
            {

            }
        }
    }
}
